#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>

typedef int ElemType;
typedef struct LinkNode{
    ElemType data;
    struct LinkNode *next;
}LinkNode;
typedef struct{
    LinkNode *front, *rear;
}LinkQueue;

void initQueue1(LinkQueue *Q);
void initQueue2(LinkQueue *Q);

int main(){

}

//无头结点初始化
void initQueue1(LinkQueue *Q){
    Q->front = NULL;
    Q->rear = NULL;
}

//有头结点初始化
void initQueue2(LinkQueue *Q){
    Q->front = (LinkNode *)malloc(sizeof(LinkNode));
    Q->rear = Q->front;
    Q->front->next = NULL;
}

//无头结点入队
bool enQueue1(LinkQueue *Q, ElemType elem){
    LinkNode *temp = (LinkNode *)malloc(sizeof(LinkNode));
    if(temp==NULL) return false;
    temp->data = elem;
    temp->next = NULL;
    if(Q->front==NULL) Q->front = temp;
    else Q->rear->next = temp;
    Q->rear = temp;
    return true;
}

//有头结点入队
bool enQueue2(LinkQueue *Q, ElemType elem){
    LinkNode *temp = (LinkNode *)malloc(sizeof(LinkNode));
    if(temp==NULL) return false;
    temp->data = elem;
    temp->next = NULL;
    Q->rear->next = temp;
    Q->rear = temp;
    return true;
}

//无头结点出队
bool outQueue1(LinkQueue *Q, ElemType *elem){
    if(Q->front==NULL) return false;
    LinkNode *temp = Q->front;
    *elem = temp->data;
    if(Q->front==Q->rear) Q->rear = Q->rear->next;
    Q->front = Q->front->next;
    free(temp);
    return true;
}

//有头结点出队
bool outQueue2(LinkQueue *Q, ElemType *elem){
    if(Q->front==Q->rear) return false;
    LinkNode *temp = Q->front->next;
    *elem = temp->data;
    if(Q->front->next==Q->rear) Q->rear = Q->front;
    Q->front->next = temp->next; 
    free(temp);
    return true;
}